/*
 * @Author: 扶苏
 * @Date: 2022年11月7日 10:31:52
 * @LastEditors: 扶苏
 * @LastEditTime: 2022年11月7日 10:31:52
 * @Description:
 */
import axios from "../network/api.request.js"
/**
 *  get请求
 * @param {*} params
 */
export const getInterfaceData = (url, params, other = {}) => {
	return axios.request({
		url: url + "?" + obj2params(params),
		method: "get",
		...other,
	})
}

/**
 *  get请求
 * @param {*} params
 */
export const getOtherInterfaceData = (url, params, other = {}) => {
	return axios.request({
		url:  url + "?" + obj2params(params),
		method: "get",
		...other
	})
}
/**
 *  post请求
 * @param {*} params
 */
export const postInterfaceData = (url, params, other = {}) => {
	return axios.request({
		url: url,
		data: params,
		method: "post",
		...other,
	})
}

/**
 *  put请求
 * @param {*} params
 */
export const putInterfaceData = (url, params, other = {}) => {
	return axios.request({
		url: url,
		data: params,
		method: "put",
		...other,
	})
}

/**
 *  delete请求
 * @param {*} params
 */
export const deleteInterfaceData = (url, params, other = {}) => {
	return axios.request({
		url: url + "?" + obj2params(params),
		method: "delete",
		...other,
	})
}

// 将对象拼接成 key1=val1&key2=val2&key3=val3 的字符串形式
function obj2params(obj) {
	var result = ""
	var item
	for (item in obj) {
		result += "&" + item + "=" + encodeURIComponent(obj[item])
	}
	if (result) {
		result = result.slice(1)
	}
	return result
}

